/*
 * ADCQueue.h
 *
 *  Created on: May 6, 2010
 *      Author: Mario Rodriguez Huizar
 */

#ifndef ADCQUEUE_H_
#define ADCQUEUE_H_

#include <queue>
#include <list>
#include <stdint.h>

//ADC_PACKET_SIZE stores the size of 16-bit data it will be taken before
//making a push on the queue
#define ADC_PACKET_SIZE	50

using namespace std;

struct ADCPacket {
	int16_t adcData[ADC_PACKET_SIZE];
	uint16_t length;
};

/// Queue used to store ADCPackets. Implemented as a thin wrapper over STL
class ADCQueue {
   /// queue of ADCPackets organized as a linked list.
   typedef queue<ADCPacket *, list<ADCPacket *> > MsgQueType;
   /// Declaration of the message queue based on the type declaration MsgQueType
   MsgQueType adcQueue;

public:
   /// \param pMsg Pointer to the message that needs to be added to the queue.
   void Add(ADCPacket *pPacket) {
      // Insert the element at the end of the queue
      adcQueue.push(pPacket);
   }

   /// retval Message Pointer to the message removed from the queue. Returns NULL if
   ///                no message is found in the queue.

   ADCPacket *Remove() {
      ADCPacket *pPacket = NULL;

      if (!adcQueue.empty()) {
         // Queue is not empty so get a pointer to the
         // first message in the queue
         pPacket = adcQueue.front();
         adcQueue.pop(); // Now remove the pointer from the message queue
      }
      return pPacket;
   }

   /// \retval int Total number of messages in the queue.
   int GetLength() const  { return adcQueue.size(); }

   //void Print() TODO
};

#endif /* ADCQUEUE_H_ */
